﻿// 1.1.3.15. Write a program that exchanges bits 3, 4 and 5 with bits 24, 25 and 26 of given 32-bit unsigned integer.

using System;

class ExchangingBits
{
    static void Main()
    {
        Begin:
        Console.Write("Please enter integer number as I suggest you \"4294901760\": ");
        uint number = uint.Parse(Console.ReadLine());
        Console.WriteLine(Convert.ToString(number, 2).PadLeft(32, '0'));
        bool isBit3One = ((number >> 3) & 1) == 1;
        bool isBit4One = ((number >> 4) & 1) == 1;
        bool isBit5One = ((number >> 5) & 1) == 1;
        bool isBit24One = ((number >> 24) & 1) == 1;
        bool isBit25One = ((number >> 25) & 1) == 1;
        bool isBit26One = ((number >> 26) & 1) == 1;        
        if (isBit3One == true)
        {
            number = number | (1u << 24);
        }
        else
        {
            number = number & (~(1u << 24));
        }
        if (isBit4One == true)
        {
            number = number | (1u << 25);
        }
        else
        {
            number = number & (~(1u << 25));
        }
        if (isBit5One == true)
        {
            number = number | (1u << 26);
        }
        else
        {
            number = number & (~(1u << 26));
        }
        if (isBit24One == true)
        {
            number = number | (1u << 3);
        }
        else
        {
            number = number & (~(1u << 3));
        }
        if (isBit25One == true)
        {
            number = number | (1u << 4);
        }
        else
        {
            number = number & (~(1u << 4));
        }
        if (isBit26One == true)
        {
            number = number | (1u << 5);
        }
        else
        {
            number = number & (~(1u << 5));
        }
        Console.WriteLine("The new number is: {0}", number);
        Console.WriteLine(Convert.ToString(number, 2).PadLeft(32, '0'));
        goto Begin;
    }
}